<template>
  <div id="app-container" style="padding:30px;">
    <el-form ref="form" label-width="14 0px">
      <el-form-item label="书籍ID和名称:">
        {{chapter.book.id}}-{{chapter.book.name}}
      </el-form-item>
      <el-form-item label="章节ID:">
        {{chapter.number}}
      </el-form-item>
      <el-form-item label="章节名称:">
        <el-input v-model="chapter.name"></el-input>
      </el-form-item>
      <el-form-item label="章节内容:">
        <el-input type="textarea" v-model="chapter.content" autosize></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="save()">提交</el-button>
        <router-link :to="'/bms/copyright/chapterlist'">
          <el-button>返回</el-button>
        </router-link>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import chapter from '@/api/copyrightin/chapter'
export default {
  data() {
    return {
      chapter: {
        id: 0
      }
    }
  },
  created() {
    this.init()
  },
  methods: {
    init() {
      if (this.$route.params && this.$route.params.id) {
        const id = this.$route.params.id
        this.view(id)
      }
    },
    view(id) {
      // 根据id进行数据查询,回显数据
      chapter.view(id)
        .then(response => {
          this.chapter = response.data.chapter
        })
    },
    save() {
      chapter.update(this.chapter)
        .then(response => {
          this.$message({
            type: 'success',
            message: '修改成功'
          })
          this.$router.push('/bms/copyright/chapterlist')
        })
    }
  }
}
</script>
